package isp.apps.example.shoppingcart.action;

import isp.apps.example.shoppingcart.persistence.ItemDirectory;
import isp.apps.example.shoppingcart.persistence.factory.ItemPersistenceFactory;

import isp.apps.example.shoppingcart.persistence.CartItemsDirectory;

import isp.apps.example.shoppingcart.persistence.factory.CartItemsPersistenceFactory;

import isp.apps.example.shoppingcart.domain.ShoppingCart;

import java.math.BigDecimal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class ListCartItemsAction
  extends ShoppingAction
{

  public List getCartItems()
  {
    ShoppingCart myCart = getCart();
    Collection myCollection = myCart.getCartItems();
    //System.out.println("Cart Items from inside ListCartItemsAction: " + myCollection);

    List l = new ArrayList(myCollection.size());
    for (Iterator iter = myCollection.iterator(); iter.hasNext(); )
    {
      l.add(iter.next());
    }
    return l;
  }

  public String execute()
  {
    if (getCart().getCartItems().size() < 1)
    {
       addActionError("Your cart is empty");
       return "CartIsEmpty";
    }
    return SUCCESS;
  }


  public int getCartSize()
  {
    ShoppingCart sc = getCart();
    return sc.getCartDistinctItemCount();
  }

}
